package io.renren.sf.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.sf.entity.CbStiffChapterPictureEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.sf.entity.CbStiffTypefaceEntity;
import io.renren.sf.service.CbStiffTypefaceService;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2021-04-26 10:46:38
 */
@RestController
@RequestMapping("sf/cbstifftypeface")
public class CbStiffTypefaceController {
    @Autowired
    private CbStiffTypefaceService cbStiffTypefaceService;


    /**
     * 硬笔字体学习分页
     */
    @GetMapping("/list")
    public R stiffTypefacePicPage(@RequestParam Map<String, Object> params) {
        long page = Long.parseLong((String) params.get("page"));
        long limit = Long.parseLong((String) params.get("limit"));
        long cid = Long.parseLong((String) params.get("cid"));
        Page<CbStiffTypefaceEntity> stiffTypefacePage = new Page<>(page, limit);
        cbStiffTypefaceService.page(stiffTypefacePage,new QueryWrapper<CbStiffTypefaceEntity>().eq("cid",cid));
        return R.ok().put("stiffTypefacePage", stiffTypefacePage);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("sf:cbstifftypeface:info")
    public R info(@PathVariable("id") Long id){
		CbStiffTypefaceEntity cbStiffTypeface = cbStiffTypefaceService.getById(id);

        return R.ok().put("cbStiffTypeface", cbStiffTypeface);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("sf:cbstifftypeface:save")
    public R save(@RequestBody CbStiffTypefaceEntity cbStiffTypeface){
		cbStiffTypefaceService.save(cbStiffTypeface);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("sf:cbstifftypeface:update")
    public R update(@RequestBody CbStiffTypefaceEntity cbStiffTypeface){
        System.out.println(cbStiffTypeface.toString());
		cbStiffTypefaceService.updateById(cbStiffTypeface);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("sf:cbstifftypeface:delete")
    public R delete(@RequestBody Long[] ids){
		cbStiffTypefaceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
